import 'package:flutter/material.dart';
import 'package:get/get.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return GetMaterialApp(
      title: "Flutter Demo",
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatelessWidget {
  const MyHomePage({super.key});
  void _alertDialog(context) async {
    var result = await showDialog(
      barrierDismissible: false,
      context: context,
      builder: (context) {
        return AlertDialog(
          title: Text("提示信息！"),
          content: Text("您确定要删除吗？"),
          actions: [
            TextButton(
              onPressed: () {
                Navigator.pop(context, "确定");
              },
              child: Text("确定"),
            ),
            TextButton(
              onPressed: () {
                Navigator.pop(context, "取消");
              },
              child: Text("取消"),
            ),
          ],
        );
      },
    );
    print(result);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text("Title")),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            ElevatedButton(
              onPressed: () {
                _alertDialog(context);
              },
              child: Text("Flutter默认的dialog"),
            ),
            ElevatedButton(
              onPressed: () {
                Get.defaultDialog(
                    title: "提示信息",
                    middleText: "您确定要删除吗？",
                    confirm: ElevatedButton(
                      onPressed: () {
                        // Navigator.pop(context);
                        Get.back();
                      },
                      child: Text("确定"),
                    ),
                    cancel: ElevatedButton(
                      onPressed: () {
                        // Navigator.pop(context);
                        Get.back();
                      },
                      child: Text("取消"),
                    ));
              },
              child: Text("Getx defailtDialog"),
            ),
            ElevatedButton(
              onPressed: () {
                Get.snackbar(
                  "提示",
                  "您还没有登录",
                  snackPosition: SnackPosition.BOTTOM,
                );
              },
              child: Text("Getx snackbar"),
            ),
            ElevatedButton(
              onPressed: () {
                Get.bottomSheet(Container(
                  color: Get.isDarkMode ? Colors.black26 : Colors.white,
                  height: 200,
                  child: Column(
                    children: [
                      ListTile(
                        leading: Icon(
                          Icons.wb_sunny_outlined,
                          color: Get.isDarkMode ? Colors.white : Colors.black87,
                        ),
                        onTap: () {
                          Get.changeTheme(ThemeData.light());
                          Get.back();
                        },
                        title: Text(
                          "白天模式",
                          style: TextStyle(
                              color: Get.isDarkMode
                                  ? Colors.white
                                  : Colors.black87),
                        ),
                      ),
                      ListTile(
                        leading: Icon(
                          Icons.wb_sunny,
                          color: Get.isDarkMode ? Colors.white : Colors.black87,
                        ),
                        onTap: () {
                          Get.changeTheme(ThemeData.dark());
                          Get.back();
                        },
                        title: Text(
                          "夜晚模式",
                          style: TextStyle(
                              color: Get.isDarkMode
                                  ? Colors.white
                                  : Colors.black87),
                        ),
                      ),
                    ],
                  ),
                ));
              },
              child: Text("Getx bottomSheet切换主题"),
            ),
          ],
        ),
      ),
    );
  }
}
